home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / text / cmanual.lzh / ACM2.lzh / Requesters / Example4.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  14KB  |  348 lines

  1. /* Example4                                                             */
  2. /* This program will open a normal window which is connected to the     */
  3. /* Workbench Screen. The window will use all System Gadgets, and will   */
  4. /* close first when the user has selected the System gadget Close       */
  5. /* window. Inside the window we have activated an Application requester */
  6. /* with a connecting gadget. The requester will first be satisfied when */
  7. /* the user has selected the gadget, and will then be deactivated. The  */
  8. /* window can now be closed.                                            */
  9.  
  10.  
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14.  
  15.  
  16. struct IntuitionBase *IntuitionBase;
  17.  
  18.  
  19.  
  20. /***************/
  21. /* THE GADGET: */
  22. /***************/
  23.  
  24. /* The coordinates for the box: */
  25. SHORT gadget_border_points[]=
  26. {
  27.    0,  0, /* Start at position (0,0) */
  28.   70,  0, /* Draw a line to the right to position (70,0) */
  29.   70, 10, /* Draw a line down to position (70,10) */
  30.    0, 10, /* Draw a line to the right to position (0,10) */
  31.    0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  32. };
  33.  
  34. /* The Border structure: */
  35. struct Border gadget_border=
  36. {
  37.   0, 0,        /* LeftEdge, TopEdge. */
  38.   1,           /* FrontPen, colour register 1. */
  39.   0,           /* BackPen, for the moment unused. */
  40.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  41.   5,           /* Count, 5 pair of coordinates in the array. */
  42.   gadget_border_points, /* XY, pointer to the array with the coord. */
  43.   NULL,        /* NextBorder, no other Border structures are connected. */
  44. };
  45.  
  46. /* The IntuiText structure: */
  47. struct IntuiText gadget_text=
  48. {
  49.   1,         /* FrontPen, colour register 1. */
  50.   0,         /* BackPen, colour register 0. */
  51.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  52.              /* change the background. */ 
  53.   4, 2,      /* LeftEdge, TopEdge. */
  54.   NULL,      /* ITextFont, use default font. */
  55.   "PRESS ME",/* IText, the text that will be printed. */
  56.   NULL,      /* NextText, no other IntuiText structures are connected. */
  57. };
  58.  
  59. struct Gadget requester_gadget=
  60. {
  61.   NULL,          /* NextGadget, no more gadgets in the list. */
  62.   40,            /* LeftEdge, 40 pixels out. */
  63.   20,            /* TopEdge, 20 lines down. */
  64.   71,            /* Width, 71 pixels wide. */
  65.   11,            /* Height, 11 pixels lines heigh. */
  66.   GADGHCOMP,     /* Flags, when this gadget is highlighted, the gadget */
  67.                  /* will be rendered in the complement colours. */
  68.                  /* (Colour 0 (00) will be changed to colour 3 (11) */
  69.                  /* (Colour 1 (01)           - " -           2 (10) */
  70.                  /* (Colour 2 (10)           - " -           1 (01) */
  71.                  /* (Colour 3 (11)           - " -           0 (00) */  
  72.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  73.   RELVERIFY|     /* the user has selected this gadget, and when the user */
  74.                  /* has released it. */
  75.   ENDGADGET,     /* When the user has selected this gadget, the */
  76.                  /* requester is satisfied, and is deactivated. */
  77.                  /* IMPORTANT! At least one gadget per requester */
  78.                  /* must have the flag ENDGADGET set. If not, the */
  79.                  /* requester would never be deactivated! */
  80.  
  81.   BOOLGADGET|    /* GadgetType, a Boolean gadget which is connected to */
  82.   REQGADGET,     /* a requester. IMPORTANT! Every gadget which is */
  83.                  /* connectd to a requester must have the REQGADGET flsg */
  84.                  /* set in the GadgetType field. */
  85.   (APTR) &gadget_border, /* GadgetRender, a pointer to our Border struc. */
  86.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  87.                  /* with an alternative image. (We complement the */
  88.                  /* colours instead) */
  89.   &gadget_text,  /* GadgetText, a pointer to our IntuiText structure. */
  90.                  /* (See chapter 3 GRAPHICS for more information) */
  91.   NULL,          /* MutualExclude, no mutual exclude. */
  92.   NULL,          /* SpecialInfo, NULL since this is a Boolean gadget. */
  93.                  /* (It is not a Proportional/String or Integer gdget) */
  94.   0,             /* GadgetID, no id. */
  95.   NULL           /* UserData, no user data connected to the gadget. */
  96. };
  97.  
  98. /***********************************************************************/
  99. /* Important notice:                                                   */
  100. /* Remember that every gadget which is connected to a requester must   */
  101. /* have the flag REQGADGET set in the GadgetType field. Remember also  */
  102. /* that at least one gadget per requester must have the ENDGADGET flag */
  103. /* set in the Activation field.                                        */
  104. /***********************************************************************/
  105.  
  106.  
  107.  
  108. /************************************/
  109. /* THE BORDER AROUND THE REQUESTER: */
  110. /************************************/
  111.  
  112. /* The coordinates for the box around the requester: */
  113. SHORT requester_border_points[]=
  114. {
  115.     0,  0, /* Start at position (0,0) */
  116.   319,  0, /* Draw a line to the right to position (319,0) */
  117.   319, 99, /* Draw a line down to position (319,99) */
  118.     0, 99, /* Draw a line to the right to position (319,99) */
  119.     0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  120. };
  121.  
  122. /* The Border structure for the requester: */
  123. struct Border requester_border=
  124. {
  125.   0, 0,        /* LeftEdge, TopEdge. */
  126.   1,           /* FrontPen, colour register 1. */
  127.   0,           /* BackPen, for the moment unused. */
  128.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  129.   5,           /* Count, 5 pair of coordinates in the array. */
  130.   requester_border_points, /* XY, pointer to the array with the coord. */
  131.   NULL,        /* NextBorder, no other Border structures are connected. */
  132. };
  133.  
  134.  
  135.  
  136. /**********************************/
  137. /* THE TEXT INSIDE THE REQUESTER: */
  138. /**********************************/
  139.  
  140. /* The IntuiText structure used to print some text inside the requester: */
  141. struct IntuiText requester_text=
  142. {
  143.   1,         /* FrontPen, colour register 1. */
  144.   0,         /* BackPen, unused since JAM1. */
  145.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  146.              /* change the background. */ 
  147.   4, 2,      /* LeftEdge, TopEdge. */
  148.   NULL,      /* ITextFont, use default font. */
  149.   "This is the requester!", /* IText, the text that will be printed. */
  150.   NULL,      /* NextText, no other IntuiText structures are connected. */
  151. };
  152.  
  153.  
  154.  
  155. struct Requester my_requester=
  156. {
  157.   NULL,              /* OlderRequester, used by Intuition. */
  158.   40, 20,            /* LeftEdge, TopEdge, 40 pixels out, 20 lines down. */
  159.   320, 100,          /* Width, Height, 320 pixels wide, 100 lines high. */
  160.   0, 0,              /* RelLeft, RelTop, Since POINTREL flag is not set, */
  161.                      /* Intuition ignores these values. */
  162.   &requester_gadget, /* ReqGadget, pointer to the first gadget. */
  163.   &requester_border, /* ReqBorder, pointer to a Border structure. */
  164.   &requester_text,   /* ReqText, pointer to a IntuiText structure. */
  165.   NULL,              /* Flags, no flags set. */
  166.   3,                 /* BackFill, draw everything on an orange backgr. */
  167.   NULL,              /* ReqLayer, used by Intuition. Set to NULL. */
  168.   NULL,              /* ReqPad1, used by Intuition. Set to NULL. */
  169.   NULL,              /* ImageBMap, no predrawn Bitmap. Set to NULL. */
  170.                      /*            (The PREDRAWN flag was not set) */
  171.   NULL,              /* RWindow, used by Intuition. Set to NULL. */
  172.   NULL               /* ReqPad2, used by Intuition. Set to NULL. */
  173. };
  174.  
  175.  
  176. /* Declare a pointer to a Window structure: */ 
  177. struct Window *my_window;
  178.  
  179. /* Declare and initialize your NewWindow structure: */
  180. struct NewWindow my_new_window=
  181. {
  182.   0,             /* LeftEdge    x position of the window. */
  183.   0,             /* TopEdge     y positio of the window. */
  184.   640,           /* Width       640 pixels wide. */
  185.   200,           /* Height      200 lines high. */
  186.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  187.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  188.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  189.                  /*             user has selected the Close window gad, */
  190.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  191.   GADGETUP,      /*             a gadge has been released. */
  192.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  193.   WINDOWCLOSE|   /*             Close Gadget. */
  194.   WINDOWDRAG|    /*             Drag gadget. */
  195.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  196.   WINDOWSIZING|  /*             Sizing Gadget. */
  197.   ACTIVATE,      /*             The window should be Active when opened. */
  198.   NULL,          /* FirstGadget No gadget connected to this window. */
  199.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  200.   "The Window",  /* Title       Title of the window. */
  201.   NULL,          /* Screen      Connected to the Workbench Screen. */
  202.   NULL,          /* BitMap      No Custom BitMap. */
  203.   140,           /* MinWidth    We will not allow the window to become */
  204.   50,            /* MinHeight   smaller than 140 x 50, and not bigger */
  205.   300,           /* MaxWidth    than 300 x 200. */
  206.   200,           /* MaxHeight */
  207.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  208. };
  209.  
  210.  
  211.  
  212. main()
  213. {
  214.   /* Boolean variable used for the while loop: */
  215.   BOOL close_me;
  216.  
  217.   /* Declare a variable in which we will store the IDCMP flag: */
  218.   ULONG class;
  219.   
  220.   /* Declare a pointer to an IntuiMessage structure: */
  221.   struct IntuiMessage *my_message;
  222.  
  223.   /* We use this variable to check if the requester has ben activated */
  224.   /* or not: */
  225.   BOOL result;
  226.  
  227.  
  228.   /* Before we can use Intuition we need to open the Intuition Library: */
  229.   IntuitionBase = (struct IntuitionBase *)
  230.     OpenLibrary( "intuition.library", 0 );
  231.   
  232.   if( IntuitionBase == NULL )
  233.     exit(); /* Could NOT open the Intuition Library! */
  234.  
  235.  
  236.  
  237.   /* We will now try to open the window: */
  238.   my_window = (struct Window *) OpenWindow( &my_new_window );
  239.   
  240.   /* Have we opened the window succesfully? */
  241.   if(my_window == NULL)
  242.   {
  243.     /* Could NOT open the Window! */
  244.     
  245.     /* Close the Intuition Library since we have opened it: */
  246.     CloseLibrary( IntuitionBase );
  247.  
  248.     exit();  
  249.   }
  250.  
  251.  
  252.  
  253.   /* We have opened the window, and everything seems to be OK. */
  254.  
  255.  
  256.  
  257.   /* We will now try to activate the requester: */
  258.   result=Request( &my_requester, my_window );
  259.  
  260.   if( !result )  /* !result is the same thing as result==FALSE */
  261.   {
  262.     /* Intuition could not activate the requester! */
  263.     /* In this case we do not need to quit since it does not matter if */
  264.     /* the requester was activated or not. I just wanted to show how */
  265.     /* you can check if you have opened or not the requester. */
  266.   
  267.     printf("Could not activate the requester!\n");
  268.   }
  269.   else
  270.   {
  271.     /* Intuition could open the requester! */
  272.     printf("Try to close the window!\n");
  273.   }
  274.  
  275.  
  276.  
  277.   close_me = FALSE;
  278.  
  279.   /* Stay in the while loop until the user has selected the Close window */
  280.   /* gadget. However, in this example the user first need to deactivate */
  281.   /* the requester before he can select the Close window gadget: */
  282.   while( !close_me )
  283.   {
  284.     /* Wait until we have recieved a message: */
  285.     Wait( 1 << my_window->UserPort->mp_SigBit );
  286.  
  287.     /* As long as we collect messages sucessfully: */
  288.     while(my_message=(struct IntuiMessage *) GetMsg(my_window->UserPort))
  289.     {
  290.       /* After we have collected the message we can read it, and save any */
  291.       /* important values which we maybe want to check later: */
  292.       class = my_message->Class;
  293.  
  294.       /* After we have read it we reply as fast as possible: */
  295.       /* REMEMBER! Do never try to read a message after you have replied! */
  296.       /* Some other process has maybe changed it. */
  297.       ReplyMsg( my_message );
  298.  
  299.       /* Check which IDCMP flag was sent: */
  300.       switch( class )
  301.       {
  302.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  303.                
  304.                /* It is first when the requester has been satisfied, the */
  305.                /* user can close the window. Remember, do never close a */
  306.                /* window if there are any active requester in it. */
  307.                
  308.                close_me=TRUE;
  309.                break;
  310.              
  311.         case GADGETDOWN:   /* The user has pressed on a gadget. */
  312.                /* Since there exist only one "nomal" gadget, we do not */
  313.                /* need to check which gadget was selected. */
  314.                
  315.                printf("Down\n");
  316.                break;
  317.              
  318.         case GADGETUP:     /* The user has released a gadget. */
  319.                /* Since there exist only one "nomal" gadget, we do not */
  320.                /* need to check which gadget was released. */
  321.                
  322.                printf("Up\n");
  323.  
  324.                /* Once the user releases this gadget the requester will */
  325.                /* be satisfied and deactivated. The user can from now on */
  326.                /* select the Close window gadget. */
  327.                
  328.                printf("Requester satisfied!\n");
  329.                printf("You may now close the window!\n");
  330.                break;
  331.       }
  332.     }
  333.   }
  334.  
  335.  
  336.  
  337.   /* We should always close the windows we have opened before we leave: */
  338.   CloseWindow( my_window );
  339.  
  340.  
  341.  
  342.   /* Close the Intuition Library since we have opened it: */
  343.   CloseLibrary( IntuitionBase );
  344.   
  345.   /* THE END */
  346. }
  347.  
  348.